package br.com.logistica.base;

import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;

import br.com.logistica.database.FactoryJPA;
import br.com.logistica.util.dto.ServiceDTO;
import br.com.util.DataBaseEnum;

public class BaseDAO {

	////subi a aplica;ao esta ser[a a primeira op;ao de banco
	protected static DataBaseEnum baseEnum = DataBaseEnum.SQLSERVER;
	protected EntityManager entityManager;
	protected EntityTransaction entityTransaction;
	protected ServiceDTO result = new ServiceDTO();

	protected void begin() {
		if (entityManager == null) {
			try {
				entityManager = FactoryJPA.getInstance(baseEnum);
			} catch (Exception e) {
				System.out.println(e);
			}
		}

		entityTransaction = entityManager.getTransaction();

		entityTransaction.begin();
	}

	protected void commit() {
		entityTransaction.commit();
	}

	protected void rollback() {
		entityTransaction.rollback();
	}
}
